using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;

namespace MinaspetroLibrary.BannerPack
{
    [Serializable()]
    public class BannerChildInfo : Csla.ReadOnlyBase<BannerChildInfo>
    {
        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private string _imagem = string.Empty;

        private string _target = string.Empty;

        private string _link = string.Empty;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }

        public string Imagem
        {
            get
            {
                return _imagem;
            }
        }

        public string ImagemString
        {
            get
            {
                CanReadProperty("ImagemString", true);
                if (_imagem.Contains("_"))
                    return _imagem.Substring(_imagem.IndexOf("_") + 1);
                return _imagem;
            }
        }

        public string Target
        {
            get
            {
                return _target;
            }
        }

        public string Link
        {
            get
            {
                return _link;
            }
        }


        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in BannerChildInfo

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static BannerChildInfo GetBannerChildInfo(SafeDataReader dr)
        {
            return new BannerChildInfo(dr);
        }

        private BannerChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString());
            _imagem = dr.GetString("Imagem");
            _target = dr.GetString("Target");
            _link = dr.GetString("Link");

        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
